<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="99px" style="padding-right: 5px;">
      <el-row>
        <el-col :span="8">
          <el-form-item label="任务名称:" prop="title" style="width: 100%;">
              <el-input
                v-model="queryParams.title"
                placeholder="请输入任务名称"
                clearable
                prefix-icon="Search"
                style="margin-bottom: 20px"
             />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="时间" prop="startTime" style="width: 100%;">
            <el-date-picker
                v-model="dateRange"
                value-format="YYYY-MM-DD"
                type="daterange"
                range-separator="-"
                start-placeholder="时间起"
                end-placeholder="时间止"
                style="width: 430px"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="8" style="position: relative;left: 60px;">
          <el-button type="danger" icon="Search" @click="handleQuery">查询</el-button>
          <el-button icon="Refresh" @click="resetQuery">重置</el-button>
        </el-col>
      </el-row>
    </el-form>
    <el-table v-loading="loading" :data="releaseTaskList" @selection-change="handleSelectionChange">
      <el-table-column label="序号" type="index" width="90"/>
      <el-table-column label="任务名称" align="left" prop="title" min-width="200"/>
      <el-table-column label="任务内容" align="left" prop="content" min-width="200" show-overflow-tooltip="true"/>
      <el-table-column label="任务阶段" align="left" prop="stage" width="150">
          <template #default="scope">
              <dict-tag :options="stageList" :value="scope.row.stage" />
          </template>
      </el-table-column>
      <el-table-column label="发起人" align="left" prop="originator" width="150"/>
      <el-table-column label="创建时间" align="left" prop="createTime" width="200">
          <template #default="scope">
             <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
      </el-table-column>
      <el-table-column label="操作" align="left" class-name="small-padding fixed-width" min-width="190">
        <template #default="scope">
          <el-button link type="danger" @click="handleView(scope.row)">查看</el-button>

          <el-divider direction="vertical" />
          <el-button link type="danger" @click="handleOpen(scope.row)" >揭榜</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 查看工作任务对话框 -->
    <view-put-leader ref="putLeaderRef" :parentMethod="parentMethod"></view-put-leader>

    <!-- 揭榜挂帅对话框 -->
    <el-dialog :title="title" v-model="open" width="600px" append-to-body>
      <el-form ref="openTaskRef" :model="form" label-width="85px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="内容" prop="content">
              <el-input v-model="form.content" type="textarea" rows="10" placeholder="请输入内容"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="附件" prop="files">
              <file-upload
                  v-model="form.files"
                  :multiple="true"
                  :limit="10"
                  :file-type="['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'pdf']"
                  :file-size="4">
              </file-upload>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="doSubmit">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="searchbill">
import { listReleaseTask, getReleaseTask, acceptTask } from "@/api/putleader/putleader";
import ViewPutLeader from './component/ViewPutLeader.vue';
const { proxy } = getCurrentInstance();
const releaseTaskList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const dateRange = ref([]);
const putLeaderRef = ref(null);
//阶段：0草稿，1申请中(寻榜)、20揭榜通过(定榜)、21揭榜驳回、30揭榜、40揭榜、50攻榜、60完成、61评榜、62奖榜、63用榜
const stageList = ref([
  {label: '草稿', value: '0'}, 
  {label: '待定榜', value: '1'}, 
  {label: '待发榜', value: '20'},
  {label: '揭榜驳回', value: '21'}, 
  {label: '待揭榜', value: '30'}, 
  {label: '待攻榜', value: '40'},
  {label: '攻榜中', value: '50'},
  {label: '挂帅成功', value: '60'}, 
  {label: '评榜', value: '61'},
  {label: '奖榜', value: '62'}, 
  {label: '用榜', value: '63'}]); 

const data = reactive({
  form: {
    id: null,
    content: null,
    files: null
  },
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    title: null,
    stage: '30',//待揭榜
    createTime: null,
    createTime2: null
  },
  rules: {
  }
});

const { form, queryParams, rules } = toRefs(data);

/** 查询揭榜挂帅列表 */
function getList() {
  loading.value = true;
  if (dateRange.value.length > 0) {
    if (dateRange.value[0] != null && dateRange.value[0] != null) {
      queryParams.value.createTime = dateRange.value[0]+' 00:00:00';
    }
    if (dateRange.value[1] != null && dateRange.value[1] != null){
      queryParams.value.createTime2 = dateRange.value[1]+' 23:59:59';
    }
  }
  listReleaseTask(queryParams.value).then(response => {
    releaseTaskList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    content: null,
    files: null
  };
  proxy.resetForm("releaseTaskRef");
}


/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  dateRange.value = [];
  queryParams.value.createTime = null;
  queryParams.value.createTime2 = null;
  proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 查看任务按钮操作 */
function handleView(row) {
  getReleaseTask(row.id).then(response => {
    proxy.$refs["putLeaderRef"].show(response.data, "查看工作任务", true);
  });
}

/** 进入揭榜弹出框 */
function handleOpen(row) {
  reset();
  title.value = "揭榜";
  form.value.id = row.id;
  open.value = true;
}

// 确定揭榜按钮
function doSubmit() {
  proxy.$refs["openTaskRef"].validate(valid => {
      if (valid) {
          acceptTask(form.value).then(response => {
            proxy.$modal.msgSuccess("揭榜成功");
            open.value = false;
            reset();
            getList();
          });
      }
  });
}

//查看工作任务回调函数
function parentMethod(data) {
  getList();
}

getList();
</script>

<style lang="scss" scoped>
.el-dialog > .el-dialog__body {
  border-top: 1px solid red;
  border-bottom: 1px solid #e9e9e9;
}
.spanUserTitle {
  height: 22px;
  background-color: rgb(255, 255, 255);
  color: rgb(51, 51, 51);
  font-size: 16px;
  text-align: left;
  font-family: PingFangSC-Regular;
}
.itemTogetherTitle {
    font-size: 14px;
    text-align: left;
    font-family: PingFangSC-Regular;
    color: rgb(153, 153, 153) !important;
    padding: 19px 59px;
}
.dialog-top-line {
  width: 100%;
  height: 1px;
  background-color: #ccc;
  position: absolute;
  left: 0px;
  top: 49px;
}
.dialog-bottom-line {
  width: 100%;
  height: 1px;
  background-color: #ccc;
  position: absolute;
  left: 0px;
  bottom: 65px;
}
.formPeopleStyle {
  position: relative;
}
.formPeopleStyle::before {
  content: "*";
  color: #F56C6C;
  position: absolute;
  left: 4px;
  top: 9px;
}
.formPeopleStyle1 {
  position: relative;
}
.formPeopleStyle1::before {
  content: "*";
  color: #F56C6C;
  position: absolute;
  left: 30px;
  top: 9px;
}
.personDiv {
  margin: 5px;
}
.singlePersonDiv {
  position: relative;
  display: block;
  width: 64px;
  height: 66px;
  float: left;
  margin-top: 10px;
  margin-bottom: 15px;
  margin-right: 10px;
  cursor: pointer;
  .closeDiv {
      position: absolute;
      top: -11px;
      right: 7px;
      font-size: 16px;
      cursor: pointer;
   }
  .circleAndText {
      width: 44px;
      height: 44px;
      line-height: 44px;
      text-align: center;
      border-radius: 50%;
      border: 1px solid #ffe3e3;
      color: #333;
      font-size: 14px;
      background-color: rgba(255, 77, 79, .06);
  }
  .bottomText {
      font-size: 14px;
      color: #595959;
      margin-top: -1px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
  }
}
</style>